﻿using System;
using System.Configuration;

namespace Webs.Controllers
{
    public class Global
    {
        public static string AppTheme = ConfigurationManager.AppSettings["AppTheme"].ToString();
        //public static string AppTheme = ConfigurationManager.AppSettings["AppTheme"].ToString();

        public static string CONNECTION_STRING = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();

        public static string SESSION_MESSAGE = "message";

        public static string ToYYYYMMDD(string date)
        {
            if (date.Length != 10)
                return "";

            string[] d = date.Split(new string[] { "/" }, StringSplitOptions.None);            
            try
            {
                return new DateTime(Convert.ToInt32(d[2].Substring(0, 4)),
                        Convert.ToInt32(d[1]),
                        Convert.ToInt32(d[0])).ToString("yyyyMMdd");                
            }
            catch
            {
                return "";
            }            
        }

        public static bool CheckDate(string date)
        {
            if (date.Length != 10)
                return false;
            
            try
            {
                int day = Convert.ToInt32(date.Substring(0, 2)),
                month = Convert.ToInt32(date.Substring(3, 2)),
                year = Convert.ToInt32(date.Substring(5, 4));

                if (month == 1 || month == 3 || month == 5 || month == 7 ||
                    month == 8 || month == 10 || month == 12)
                {
                    if (day < 0 || day > 31)
                        return false;
                }
                else if (month == 2)
                {
                    if (year % 4 != 0)
                    {
                        if (day < 0 || day > 28)
                            return false;
                    }
                    else
                    {
                        if (day < 0 || day > 29)
                            return false;
                    }
                }
                else
                {
                    if (day < 0 || day > 30)
                        return false;
                }
            }
            catch {
                return false;
            }
           
            return true;
        }
    }// end class

    public class DBMode
    {
        public static int INSERT = 1;
        public static int UPDATE = 2;
        public static int DELETE = 3;
    }
}
